/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eproject_sem2;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author ZER0
 */
public class Prices_by_weight extends javax.swing.JFrame {
    private static final long serialVersionUID = 1L;

    ListOfPrice_Sever a = new ListOfPrice_Sever();
    VotesSent_Sever s = new VotesSent_Sever();

    public JInternalFrame getItnfPriceByWeight() {
        return itnfPriceByWeight;
    }
    

    /**
     * Creates new form Prices_by_weight
     */
    public Prices_by_weight() {
        initComponents();
        tfGWeightE.setText(s.CreateID("Prices_by_weight", "W"));
        a.ShowTable("STTW", "GroupWeightID", "GroupWeightName", "PriceOfGroupWeight", "Prices_by_weight", tbPIByWeightE);
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        itnfPriceByWeight = new javax.swing.JInternalFrame();
        jpPIByWeightE = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbPIByWeightE = new javax.swing.JTable();
        jpUpdatePriceE2 = new javax.swing.JPanel();
        lbGWeightIDSearchE = new javax.swing.JLabel();
        tfGWeightE = new javax.swing.JTextField();
        lbGWeightNameE = new javax.swing.JLabel();
        tfGWeightNameE = new javax.swing.JTextField();
        lbPGWeightE = new javax.swing.JLabel();
        tfPGWeightE = new javax.swing.JTextField();
        btEditE2 = new javax.swing.JButton();
        btResetE2 = new javax.swing.JButton();
        btExitE2 = new javax.swing.JButton();
        btAddE2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        itnfPriceByWeight.setClosable(true);
        itnfPriceByWeight.setVisible(true);

        jpPIByWeightE.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1), "Price information by weight", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        tbPIByWeightE.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "STTW", "GroupWeightID", "GroupWeightName", "PriceOfGroupWeight"
            }
        ));
        tbPIByWeightE.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbPIByWeightEMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tbPIByWeightE);

        javax.swing.GroupLayout jpPIByWeightELayout = new javax.swing.GroupLayout(jpPIByWeightE);
        jpPIByWeightE.setLayout(jpPIByWeightELayout);
        jpPIByWeightELayout.setHorizontalGroup(
            jpPIByWeightELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        jpPIByWeightELayout.setVerticalGroup(
            jpPIByWeightELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE)
        );

        jpUpdatePriceE2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Update price", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        lbGWeightIDSearchE.setText("GroupWeightID:");

        lbGWeightNameE.setText("GroupWeightName:");
        lbGWeightNameE.setToolTipText("");

        lbPGWeightE.setText("PriceOfGroupWeight:");

        btEditE2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/eproject_sem2/Icon/1484902.png"))); // NOI18N
        btEditE2.setText("Edit");
        btEditE2.setToolTipText("");
        btEditE2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEditE2ActionPerformed(evt);
            }
        });

        btResetE2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/eproject_sem2/Icon/icon_reset.png"))); // NOI18N
        btResetE2.setText("Reset");
        btResetE2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btResetE2ActionPerformed(evt);
            }
        });

        btExitE2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/eproject_sem2/Icon/Exit.png"))); // NOI18N
        btExitE2.setText("Exit");
        btExitE2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExitE2ActionPerformed(evt);
            }
        });

        btAddE2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/eproject_sem2/Icon/Open-Folder-Add-icon.png"))); // NOI18N
        btAddE2.setText("ADD");
        btAddE2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddE2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpUpdatePriceE2Layout = new javax.swing.GroupLayout(jpUpdatePriceE2);
        jpUpdatePriceE2.setLayout(jpUpdatePriceE2Layout);
        jpUpdatePriceE2Layout.setHorizontalGroup(
            jpUpdatePriceE2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpUpdatePriceE2Layout.createSequentialGroup()
                .addGroup(jpUpdatePriceE2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpUpdatePriceE2Layout.createSequentialGroup()
                        .addGap(186, 186, 186)
                        .addComponent(lbGWeightIDSearchE)
                        .addGap(26, 26, 26)
                        .addComponent(tfGWeightE, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpUpdatePriceE2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lbGWeightNameE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tfGWeightNameE, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lbPGWeightE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tfPGWeightE, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(67, Short.MAX_VALUE))
            .addGroup(jpUpdatePriceE2Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(btAddE2, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btEditE2, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btResetE2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btExitE2, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36))
        );
        jpUpdatePriceE2Layout.setVerticalGroup(
            jpUpdatePriceE2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpUpdatePriceE2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpUpdatePriceE2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbGWeightIDSearchE)
                    .addComponent(tfGWeightE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpUpdatePriceE2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbGWeightNameE)
                    .addComponent(tfGWeightNameE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbPGWeightE)
                    .addComponent(tfPGWeightE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpUpdatePriceE2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btResetE2)
                    .addComponent(btExitE2)
                    .addComponent(btEditE2)
                    .addComponent(btAddE2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout itnfPriceByWeightLayout = new javax.swing.GroupLayout(itnfPriceByWeight.getContentPane());
        itnfPriceByWeight.getContentPane().setLayout(itnfPriceByWeightLayout);
        itnfPriceByWeightLayout.setHorizontalGroup(
            itnfPriceByWeightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpPIByWeightE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, itnfPriceByWeightLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpUpdatePriceE2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        itnfPriceByWeightLayout.setVerticalGroup(
            itnfPriceByWeightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(itnfPriceByWeightLayout.createSequentialGroup()
                .addComponent(jpPIByWeightE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jpUpdatePriceE2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(itnfPriceByWeight)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(itnfPriceByWeight)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tbPIByWeightEMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbPIByWeightEMouseClicked
        // TODO add your handling code here:
        tbPIByWeightE.getSelectedRow();
        tfGWeightE.setText((String) tbPIByWeightE.getValueAt(tbPIByWeightE.getSelectedRow(), 1));
        tfGWeightNameE.setText((String) tbPIByWeightE.getValueAt(tbPIByWeightE.getSelectedRow(), 2));
        tfPGWeightE.setText(Float.toString((float) tbPIByWeightE.getValueAt(tbPIByWeightE.getSelectedRow(), 3)));
    }//GEN-LAST:event_tbPIByWeightEMouseClicked

    private void btEditE2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEditE2ActionPerformed
        // TODO add your handling code here:
        int result = JOptionPane.showConfirmDialog(this, "Do you want to edit the information?", "Information", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
        if (result == JOptionPane.YES_OPTION) {
            if ((a.UpdatePrice(tfGWeightE.getText(), tfGWeightNameE.getText(), Float.parseFloat(tfPGWeightE.getText()), "Prices_by_weight", "GroupWeightID", "GroupWeightName", "PriceOfGroupWeight")) == true) {
                a.ShowTable("STTW", "GroupWeightID", "GroupWeightName", "PriceOfGroupWeight", "Prices_by_weight", tbPIByWeightE);
            } else {
                JOptionPane.showMessageDialog(rootPane, "Data error");
            }
        }
    }//GEN-LAST:event_btEditE2ActionPerformed

    private void btResetE2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btResetE2ActionPerformed
        // TODO add your handling code here:
        a.ShowTable("STTW", "GroupWeightID", "GroupWeightName", "PriceOfGroupWeight", "Prices_by_weight", tbPIByWeightE);
        tfGWeightE.setText(s.CreateID("Prices_by_weight", "W"));
        tfGWeightNameE.setText(null);
        tfPGWeightE.setText(null);
    }//GEN-LAST:event_btResetE2ActionPerformed

    private void btExitE2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExitE2ActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_btExitE2ActionPerformed

    private void btAddE2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddE2ActionPerformed
        // TODO add your handling code here:
        try {
            try {
                if (a.CheckIDPrice(tfGWeightE.getText(), "Prices_by_weight") != -1) {
                    JOptionPane.showMessageDialog(this, "No add,ID already exists,You can to edit the information?");
                } else {
                    if ((a.InsertPrice(tfGWeightE.getText(), tfGWeightNameE.getText(), Float.parseFloat(tfPGWeightE.getText()), "Prices_by_weight", "GroupWeightID", "GroupWeightName", "PriceOfGroupWeight")) == true) {
                        a.ShowTable("STTW", "GroupWeightID", "GroupWeightName", "PriceOfGroupWeight", "Prices_by_weight", tbPIByWeightE);
                    } else {
                        JOptionPane.showMessageDialog(rootPane, "Error data enter");
                    }
                }
            } catch (SQLException ex) {
                Logger.getLogger(Prices_by_weight.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Prices_by_weight.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btAddE2ActionPerformed

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAddE2;
    private javax.swing.JButton btEditE2;
    private javax.swing.JButton btExitE2;
    private javax.swing.JButton btResetE2;
    private javax.swing.JInternalFrame itnfPriceByWeight;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPanel jpPIByWeightE;
    private javax.swing.JPanel jpUpdatePriceE2;
    private javax.swing.JLabel lbGWeightIDSearchE;
    private javax.swing.JLabel lbGWeightNameE;
    private javax.swing.JLabel lbPGWeightE;
    private javax.swing.JTable tbPIByWeightE;
    private javax.swing.JTextField tfGWeightE;
    private javax.swing.JTextField tfGWeightNameE;
    private javax.swing.JTextField tfPGWeightE;
    // End of variables declaration//GEN-END:variables
}
